/**
 * com.monte.basedata.TreeEntity.java
 * create by FengMy from 2013
 */
package com.monte.entity;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

/**
 * @描述:树形结构实体基类
 * @author FengMy
 * @since 2013-3-25
 */
@MappedSuperclass
public abstract class TreeEntity<T extends TreeEntity<?>> extends DataEntity {
	private static final long serialVersionUID = 8329875188751241181L;
	
	/**
	 * 父节点
	 */
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="FKPARENTID",nullable=true)
	protected T parent;
	
	/**
	 * 长编码
	 */
	@Column(name="FLONGNUMBER",length=255)
	private String longNumber;
	
	/**
	 * 等级
	 */
	@Column(name="FLEVEL")
	private Integer level;
	
	/**
	 * 叶子节点
	 */
	@Column(name="FLEAF")
	private boolean leaf;
	
	/**
	 * 下级节点
	 */
	@Transient
	private List<T> children;
	
	public String getLongNumber() {
		return longNumber;
	}

	public void setLongNumber(String longNumber) {
		this.longNumber = longNumber;
	}

	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	public boolean isLeaf() {
		return leaf;
	}

	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}

	public T getParent() {
		return parent;
	}

	public void setParent(T parent) {
		this.parent = parent;
	}

	/**
	 * 允许在有子节点的情况下删除
	 * @return
	 */
	public boolean allowDeleteHasChild(){
		return false;
	}

	public List<T> getChildren() {
		return children;
	}

	public void setChildren(List<T> children) {
		this.children = children;
	}
}
